//
//  VVTabBarRedPointManager.m
//  VOVA
//
//  Created by fwzhou on 2020/3/25.
//  Copyright © 2020 iOS. All rights reserved.
//

#import "LBTabBarRedPointManager.h"
#import "LBTabBarNumRedPointView.h"
#import "LBViewController.h"

@interface LBTabBarRedPointManager ()

@property (nonatomic, weak) LBTabBarController *tabBarController;

@end

@implementation LBTabBarRedPointManager

+ (instancetype)manager
{
    static LBTabBarRedPointManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[self alloc] init];
    });
    return manager;
}

- (void)config:(LBTabBarController *)tabBarController
{
    self.tabBarController = tabBarController;
    [self showMyNumber];
}

- (void)showMyNumber
{
    LBTabBarNumRedPointView *numRedPointView =
    (LBTabBarNumRedPointView *)[self.tabBarController getRedPointViewWithClassName:[LBViewController class]];
    if (!numRedPointView ||
        ![numRedPointView isKindOfClass:[LBTabBarNumRedPointView class]]) {
        numRedPointView = [[LBTabBarNumRedPointView alloc] init];
        [self.tabBarController addRedPointViewWithClassName:[LBViewController class] redPointView:numRedPointView];
    }
    NSInteger number = 4;
    NSString *value;
    if (number <= 0) {
        numRedPointView.hidden = YES;
    } else {
        numRedPointView.hidden = NO;
        if (number >= 100) {
            value = @"99+";
        } else {
            value = [NSString stringWithFormat:@"%ld", (long)number];
        }
        NSDictionary * model = @{
            @"num" : value
        };
        [numRedPointView updateWithModel:model];
    }
}

@end
